package com.ruoyi.module.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.module.domain.DictTag;
import com.ruoyi.module.service.IDictTagService;

/**
 * 词典标签Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/module/dict/tag")
public class DictTagController extends BaseController
{
    @Autowired
    private IDictTagService dictTagService;

    /**
     * 查询标签列表
     */
    @PreAuthorize("@ss.hasPermi('module:dict:tag:list')")
    @GetMapping("/list")
    public TableDataInfo list(DictTag dictTag)
    {
        startPage();
        List<DictTag> list = dictTagService.selectDictTagList(dictTag);
        return getDataTable(list);
    }

    /**
     * 查询所有标签
     */
    @GetMapping("/all")
    public AjaxResult all()
    {
        List<DictTag> list = dictTagService.selectDictTagAll();
        return success(list);
    }

    /**
     * 根据词典ID查询标签列表
     */
    @GetMapping("/book/{bookId}")
    public AjaxResult listByBookId(@PathVariable("bookId") String bookId)
    {
        List<DictTag> list = dictTagService.selectDictTagListByBookId(bookId);
        return success(list);
    }

    /**
     * 根据ID查询标签详情
     */
    @PreAuthorize("@ss.hasPermi('module:dict:tag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dictTagService.selectDictTagById(id));
    }

    /**
     * 新增标签
     */
    @PreAuthorize("@ss.hasPermi('module:dict:tag:add')")
    @Log(title = "词典标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DictTag dictTag)
    {
        dictTag.setCreateBy(getUsername());
        return toAjax(dictTagService.insertDictTag(dictTag));
    }

    /**
     * 修改标签
     */
    @PreAuthorize("@ss.hasPermi('module:dict:tag:edit')")
    @Log(title = "词典标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DictTag dictTag)
    {
        dictTag.setUpdateBy(getUsername());
        return toAjax(dictTagService.updateDictTag(dictTag));
    }

    /**
     * 删除标签
     */
    @PreAuthorize("@ss.hasPermi('module:dict:tag:remove')")
    @Log(title = "词典标签", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dictTagService.deleteDictTagByIds(ids));
    }
}

